package com.example.m2.controller;


import com.example.service1.common.pojo.M2;
import com.example.m2.service.M2Service;
import com.example.service1.common.api.entity.ResponseResult;
import io.seata.core.context.RootContext;
import io.seata.core.exception.TransactionException;
import io.seata.spring.annotation.GlobalTransactional;
import io.seata.tm.api.GlobalTransactionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/m2")
public class M2Controller {

    @Autowired
    M2Service m1Service;

//    @Transactional
//    @GlobalTransactional(name = "m12",rollbackFor = Exception.class)
    @GetMapping("/update/info")
    public ResponseResult<M2> updateM2() throws TransactionException {
//        GlobalTransactionContext.reload(RootContext.getXID()).rollback();
        M2 m1 = m1Service.updateInfo(M2.defaultCreate());

        System.out.println(RootContext.getXID());
        return ResponseResult.success(m1);
    }
}
